<!--
 * @Author: your name
 * @Date: 2021-04-08 19:17:26
 * @LastEditTime: 2021-04-09 18:31:36
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \shop\training-group-5-warehouse\dianshang\src\views\Group\components\CityForm.vue
-->
<!--地址列表-->
<template>
  <div class="city" :class="isShow?'active':'actives'">
    <header>
      <span @click="handleSetIsShow">&lt;</span>
      <h2>我的收货地址</h2>
      <span></span>
    </header>
    <main>
      <dl v-for="(item,index) in cityData" :key="item.id">
        <div>
          <h2>
            <dt>
              <span>{{item.name.slice(0,1)}}</span>
            </dt>
            <dd>
              <p>
                <span>{{item.name}}</span>
                <span>{{item.phoneNumber}}</span>
              </p>
              <p>
                <span>{{item.region}}</span>
              </p>
              <p>
                <span>{{item.detailed}}</span>
              </p>
            </dd>
          </h2>
          <van-icon name="edit" size="20px" color="#b1b1b1" @click="handleCompile(item)" />
        </div>
        <div>
          <span>
            <input
              name="defaultCity"
              type="radio"
              :checked="index===cityIndex"
              @input="handleMonitor(index)"
            />默认地址
          </span>
          <span @click="handleDeleteCity(item.id,index)">删除</span>
        </div>
      </dl>
    </main>
    <footer>
      <button @click="handleAddCity">+ 添加收货地址</button>
    </footer>
  </div>
</template>

<script>
export default {
  props: {
    isShow: {
      type: Boolean,
      default: false,
      require: true,
    },
    cityData: {
      type: Array,
      default: () => [],
      require: false,
    },
    cityIndex: {
      type: Number,
      default: 0,
      require: false,
    },
  },
  methods: {
    //左箭头
    handleSetIsShow() {
      this.$emit("handleSetIsShow");
    },
    //添加地址按钮
    handleAddCity() {
      this.$emit("handleAddCity");
    },
    //删除地址
    handleDeleteCity(id, cityIndex) {
      this.$emit("handleDeleteCity", { id, cityIndex });
    },
    //编辑
    handleCompile(values) {
      this.$emit("handleCompile", values);
    },
    //默认地址
    handleMonitor(cityIndex) {
      this.$emit("handleMonitor", cityIndex);
    },
  },
};
</script>

<style lang="scss" scoped>
.city {
  width: 100%;
  height: 100%;
  background: #fff;
  position: fixed;
  left: 0;
  bottom: -100%;
  transition: all 1s;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  header {
    width: 100%;
    height: 46px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 10px;
    span {
      color: #c1c1c1;
    }
    h2 {
      font-size: 18px;
    }
  }
  main {
    flex: 1;
    overflow-x: scroll;
    display: flex;
    flex-direction: column;
    background: #f5f5f5;
    dl {
      width: 100%;
      height: 150px;
      margin: 10px 0;
      background: #fff;
      display: flex;
      flex-direction: column;
      overflow: hidden;
      padding: 0 10px;
      color: #575757;
      div:nth-child(1) {
        flex: 1;
        display: flex;
        align-items: center;
        justify-content: space-between;
        font-size: 12px;
        h2 {
          display: flex;
          align-items: center;
          dt {
            width: 30px;
            height: 30px;
            border-radius: 50%;
            span {
              display: inline-block;
              width: 100%;
              height: 100%;
              border-radius: 50%;
              text-align: center;
              line-height: 30px;
              color: #fe8d89;
              background: #ffdddc;
            }
          }
          dd {
            margin: 0 20px;
            p {
              margin: 5px 0;
            }
            p:nth-child(1) {
              span:nth-child(1) {
                font-weight: 600;
                font-size: 14px;
              }
              span:nth-child(2) {
                margin: 0 5px;
              }
            }
          }
        }
      }
      div:nth-child(2) {
        width: 100%;
        height: 46px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        font-size: 12px;
        span {
          display: flex;
          align-items: center;
          input {
            margin-right: 5px;
          }
        }
      }
    }
  }
  footer {
    width: 100%;
    height: 46px;
    display: flex;
    align-items: center;
    justify-content: center;
    button {
      width: 100%;
      height: 100%;
      font-size: 16px;
      background: -webkit-linear-gradient(left, #ff4f66, #ff425e);
      border: none;
      outline: none;
      color: #fff;
    }
  }
}
.city.active {
  bottom: 0;
}
.city.actives {
  bottom: -100%;
}
</style>